/**
 * 
 */
package com.sony.csl.positioning.publictransport.midlet.ui;

import java.util.Enumeration;
import java.util.Vector;

import javax.microedition.lcdui.*;

import com.sony.csl.j2me.midlet.CSLMIDlet;
import com.sony.csl.j2me.ui.CSLList;
import com.sony.csl.positioning.publictransport.model.place_context.PlaceContext;


/**
 * @author mstevens
 *
 */
public class PlaceList extends CSLList
{

	//List:
	private Vector options;
	
	//UI:
	private Font smallFont;
	private Command cmdPick;
	private Command cmdMinimize;
	private Command cmdExit;
	
	/**
	 * @param listType
	 * @param midlet
	 */
	public PlaceList(CSLMIDlet midlet)
	{
		super("", List.IMPLICIT, midlet);
	}

	/**
	 * @see com.sony.csl.j2me.ui.CSLList#initializeList()
	 */
	protected void initializeList()
	{
		smallFont = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN, Font.SIZE_SMALL);

		//Commands:
		cmdPick = new Command("Choose", Command.ITEM, 1);
		cmdMinimize = new Command("Minimize", Command.ITEM, 2);
		cmdExit = new Command("Stop & Exit", Command.ITEM, 2);
		this.setSelectCommand(cmdPick);
		this.addCommand(cmdMinimize, false);
		this.addCommand(cmdExit, false);
		this.updateCommands(); //!!!
	}
		
	public void listPlaceContexts(Vector placeContexts)
	{
		this.deleteAll();
		options = placeContexts;
		Enumeration pcEnum = placeContexts.elements();
		while(pcEnum.hasMoreElements())
		{
			String label = ((PlaceContext) pcEnum.nextElement()).getPreActivedDisplayString();
			label = Character.toUpperCase(label.charAt(0)) + label.substring(1);
			int idx = this.append(label, null);
			this.setFont(idx, smallFont);
		}
		setSelectedIndex(0, true);
	}
	
	public Object getChosenOption()
	{
		if(getSelectedIndex() > -1)
			return options.elementAt(getSelectedIndex());
		else
			return null;
	}

	/**
	 * @return the cmdPick
	 */
	public Command getCmdPick()
	{
		return cmdPick;
	}
	
	/**
	 * @return the cmdExit
	 */
	public Command getCmdExit()
	{
		return cmdExit;
	}

	/**
	 * @return the cmdMinimize
	 */
	public Command getCmdMinimize()
	{
		return cmdMinimize;
	}

}
